<?php

namespace app\api\model;

use think\Db;

class UserModel extends Model
{

    //总条数
    public function count()
    {
        $list = Db::table('user_info')->select();
        $list_length = count($list);
        return $list_length;
    }

    //分页查询
    public function list($page, $limit)
    {
        return Db::table('user_info')->page($page, $limit)->select();
    }

    public function getUserData($user_name)
    {
        return Db::table('user_info')->where(['user_name' => $user_name])->field('id,user_name,password,tel,nick_name')->find();
    }

    public function add($data)
    {
        return Db::table('user_info')->insert($data);
    }

    public function updateByUsername($user_name, $data)
    {
        return Db::table('user_info')->where('user_name=' . $user_name)->update($data);
    }

    public function updatePassword($user_name, $data)
    {
        return Db::table('user_info')->where('user_name=' . $user_name)->update($data);
    }


    public function searchByName($user_name)
    {
        return Db::table('user_info')->where(['user_name' => $user_name])->find();
    }

    public function findIdByName($user_name)
    {
        return Db::table('user_info')->where(['user_name' => $user_name])->value('id');
    }

}